﻿using System;

class Excel_Columns
{
    static void Main()
    {
        int n = int.Parse(Console.ReadLine());

        long colNumber = 0;

        // 26 numbers count system: X*Math.Pow(26, 0) + ... + X*Math.Pow(26, n-1)
 
        for (int i = n - 1; i >= 0; i--)
        {
            colNumber += (Convert.ToChar(Console.ReadLine()) - 64) * (long)Math.Pow(26, i);
        }

        Console.WriteLine(colNumber);
    }
}
